<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>反核销费用 - TMS</title>
    <link rel="stylesheet" href="/view/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/view/frame/static/css/global.css?v=1.0">
    <style>
      body {margin:20px;}
    </style>
  </head>
  <body>
    <form class="layui-form" autocomplete="off">
      <!--start:表格列表-->
      <table class="layui-hide" id="tableList" lay-filter="tbar"></table>
      <!--end:表格列表-->
      <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit" style="width:150px;">反核销</button>
        <button class="layui-btn layui-btn-primary btn-cancel" type="button" style="width:150px;">取消</button>
      </div>
    </form>
  </body>
  <script charset="utf-8" src="/view/frame/layui/layui.js"></script>
  <script charset="utf-8" src="/view/frame/static/js/jquery.min.js?v=1.0"></script>
  <script charset="utf-8" src="/view/tms/static/js/tms_index.js?v=1219"></script>
  <script charset="utf-8" src="/view/frame/static/js/layui.district.js?v=1.0"></script>
  <script charset="utf-8" src="/view/tms/static/js/tms_tab.js?v=1.0"></script>
  <script charset="utf-8" src="/view/frame/static/js/lang_zh_CN.js?v=1.0"></script>
  
  <script charset="utf-8" src="/view/frame/static/js/errorCodeMap.js"></script>
  <script charset="utf-8" src="/view/frame/static/js/HC.js?v=1.4"></script>
  <script charset="utf-8" src="/view/tms/static/js/validator.js"></script>
  <script charset="utf-8" src="/view/tms/static/js/bizUtil.js"></script>
  
  <script>
  layui.use(['form', 'layer', 'table', 'laydate'], function(){
    var form = layui.form,
        layer = layui.layer,
        table = layui.table,
        laydate = layui.laydate,
        tmsTab = layui.tms_tab,
        $ = layui.jquery;

    var $orderId = $.trim(getUrlParam("orderId")),
        $lastModifyTime = $.trim(getUrlParam("lastModifyTime"));
    setTableData($orderId);

    //方法级渲染
    function setTableData($orderId){
      typeof $orderId != 'undefined' ? $orderId = $orderId : $orderId = '';
      var $pageSize = 15;

      table.render({
        elem: '#tableList',
        url: '/ucenter/general/finance/revenueRecord/search.shtml?orderId=' + $orderId,
        response: {
          statusCode: 'SUCCESS',
          countName: 'objects.total', //数据总数的字段名称，默认：count
          dataName: 'objects'
        },
        request: {
          pageName: 'pageNum', //页码的参数名称，默认：page
          limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        cols: [[
          {checkbox: true, fixed: true},
          {field:'revenueNo', title: '收款单号', width:170},
          {field:'customerName', title: '客户简称', width:130},
          {field:'billNo', title: '账单号', width:170},
          {field:'billMonth', title: '账期', width:100},
          {field:'accountNo', title: '收款账号', width:190},
          {field:'price', title: '收款金额', width:110},
          {field:'revenueDate', title: '收款日期', width:110, templet:'#revenueDateTpl'},
          {field:'described', title: '摘要', width:150},
          {field:'status', title: '状态', width:120, templet:'#statusTpl'},
          {field:'creator', title: '创建人', width:110},
          {field:'createDate', title: '创建时间', width:190, templet:'#createDateTpl'}
        ]],
        id: 'dataReload',
        page: false,
        limits: [15, 30, 50, 100],
        limit: $pageSize,
        height: 'full-130',
        even: true,
        done: function(res, curr, count){}
      });
    }

    //监听提交
    form.on('submit(submit)', function(data){
      var checkStatus = table.checkStatus('dataReload'),
          data = checkStatus.data;
      if(data.length == 0){
        parent.layer.alert('请选择需反核销的数据！');
        return false;
      }else{
        parent.layer.confirm('确定要反核销这些记录吗？',function(){
          var idArr = [];
          var count = 0;
          $(data).each(function(i,value){
            if(value.status == 2){
              parent.layer.alert('撤销状态的记录不能进行反核销！');
              count = 1;
              return false;
            }else{
              idArr.push(value.id);
            }
          });

          if(count == 0){
            //数据源
            var $saveData = {
              reveId: idArr,
              lastModifyTime: $lastModifyTime
            }
            
            //调用接口
            $.ajax({
              type:"POST", 
              url:"/ucenter/general/finance/confirm/unConfirm.shtml",
              dataType:"json",      
              contentType:"application/json",               
              data:JSON.stringify($saveData),
              success:function(d){
                var $code = d.code,
                    $msg = d.msg,
                    $objects = d.objects;
                   
                if($code === 'SUCCESS'){
                  parent.layer.alert("保存成功", {
                    closeBtn: 0,
                    yes: function(index){
                      var layId = $(window.parent.document).find("li.layui-this").attr("lay-id");
                      $(window.parent["f" + layId].document).find('.btn-search').click();
                      parent.layer.closeAll();
                    }
                  });
                }else{
                  parent.layer.alert('保存信息失败，请重新填写！');
                }
              }
            });
          }
        });
        return false;
      }
    });

    $(".btn-cancel").on("click",function(){
      parent.layer.close(parent.layer.index);
    });
  });
  </script>
  <script type="text/html" id="revenueDateTpl">
    {{new Date(d.revenueDate).format("yyyy-MM-dd")}}
  </script>
  <script type="text/html" id="createDateTpl">
    {{new Date(d.createDate).format("yyyy-MM-dd")}}
  </script>
  <script type="text/html" id="statusTpl">
    {{#  if(d.status == '1'){ }}
      已到帐
    {{#  } else if(d.status == '2'){ }}
      撤销
    {{#  } }}
  </script>
</html>